/////////////////////////////////////////////////////////////////////////////
//
//  Fifteen Puzzle
//  Kolonitsky Developers Alliance (c) 2012
//  All rights received
//
/////////////////////////////////////////////////////////////////////////////

package view.states
{

    import caurina.transitions.Tweener;

    import flash.display.Bitmap;
    import flash.display.Sprite;
    import flash.events.Event;

    import model.vo.PuzzleVO;

    import org.osmf.events.TimeEvent;

    import view.skins.MenuSkin;

    public class MenuState implements IState
    {
        //-----------------------------
        // game
        //-----------------------------

        private var _game:PuzzleVO = null;

        public function get game():PuzzleVO
        {
            return _game;
        }


        //-------------------------------------------------------------------
        // Methods
        //-------------------------------------------------------------------

        public function MenuState()
        {
            _skin = new MenuSkin();
        }


        //-------------------------------------------------------------------
        //
        //  IState Implementation
        //
        //-------------------------------------------------------------------

        public function displayGame(game:PuzzleVO):void
        {
            _game = game;
            if (game.isComplete)
                _skin.gameRunning = 2;
            else if (game.duration)
                _skin.gameRunning = 1;
            else
                _skin.gameRunning = 0;
        }

        public function activate():void
        {
            var sw:Number = _skin.stage.stageWidth || _skin.stage.width;
            var sh:Number = _skin.stage.stageHeight || _skin.stage.height;
            for (var i:int = 0; i < Config.BOARD_CELLS; i++)
            {
                var tile:Bitmap = _number[i];
                Tweener.addTween(tile,  {
                    x: Math.random() * sw,
                    y: Math.random() * sh,
                    rotation: Math.random() * 360,
                    alpha: 1.0,
                    time: Config.TILE_ANIMATION_SPEED,
                    delay: 0.1 * i
                })
            }
        }

        public var _skin:MenuSkin = null;

        public function get skin():Sprite
        {
            return _skin;
        }

        private var _number:Vector.<Bitmap>;

        public function get numbers():Vector.<Bitmap>
        {
            return _number;
        }

        public function set numbers(value:Vector.<Bitmap>):void
        {
            _number = value;
        }




        //-------------------------------------------------------------------
        //
        //  Private
        //
        //-------------------------------------------------------------------


    }
}
